﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsGhiNhatKyChungTu
    {
        private string mDienGiai = "";
        private string mDienGiaiTongHop = "";
        private string mKhoaBoPhanCo = "";
        private string mKhoaBoPhanNo = "";
        private string mKhoaChungTu = "";
        private string mKhoaDoiTuongCo = "";
        private string mKhoaDoiTuongNo = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDongCo = "";
        private string mKhoaHopDongNo = "";
        private string mKhoaKhoanMucCo = "";
        private string mKhoaKhoanMucNo = "";
        private string mKhoaSanPhamCo = "";
        private string mKhoaSanPhamNo = "";
        private string mKhoaTaiKhoanCo = "";
        private string mKhoaTaiKhoanNo = "";
        private string mLoaiTien = "";
        private string mNamThang = "";
        private string mNgayChungTu = "";
        private string mNgayHoaDon = "";
        private int mSend = 0;
        private string mSoChungTu = "";
        private string mSoHoaDon = "";
        private double mSoPhatSinh = 0.0;
        private double mSoPhatSinhNT = 0.0;
        private string mSoSeri = "";
        private double mTyGia = 0.0;

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM GL_NhatKyChungTu WHERE KhoaChungTu = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mSoHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNgayHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mSoSeri = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanNo = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongNo = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhanNo = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPhamNo = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDongNo = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhoanMucNo = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongCo = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPhamCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDongCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhoanMucCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinhNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinh = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetString));
                    this.mDienGiaiTongHop = Conversions.ToString(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetInt32));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool LoadCanTruCongNo(string pKhoa, string pKhoaTaiKhoanCo)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM GL_NhatKyChungTu WHERE KhoaChungTu = '" + pKhoa + "' and KhoaTaiKhoanCo = '" + pKhoaTaiKhoanCo + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mSoHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNgayHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mSoSeri = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanNo = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongNo = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhanNo = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPhamNo = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDongNo = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhoanMucNo = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongCo = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhanCo = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPhamCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDongCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhoanMucCo = Conversions.ToString(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinhNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinh = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetString));
                    this.mDienGiaiTongHop = Conversions.ToString(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetInt32));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool LoadSum(string pKhoa, string pKhoaTaiKhoanCo)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT KhoaChungTu, sum(SoPhatSinhNT) SoPhatSinhNT, sum(SoPhatSinh) SoPhatSinh FROM GL_NhatKyChungTu WHERE KhoaChungTu = '" + pKhoa + "'  and KhoaTaiKhoanCo = '" + pKhoaTaiKhoanCo + "' GROUP BY KhoaChungTu ";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoaChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mSoPhatSinhNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinh = Conversions.ToDouble(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetDecimal));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool LoadSumDetail(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT A.KhoaChungTu, A.SoChungTu, A.NgayChungTu, A.SoHoaDon, A.NgayHoaDon, A.LoaiTien, A.TyGia,        A.SOTIENGOCNT - isnull(B.SOTIENGOCNT,0) as SoPhatSinhNT, A.SOTIENGOC - isnull(B.SOTIENGOC,0) as SoPhatSinhNT,        A.DienGiai, A.KhoaDoiTuongNo, A.KhoaTaiKhoanNo FROM        (SELECT NK.KhoaChungTu, NK.SoChungTu, dbo.Char2Date(NK.NgayChungTu) as NgayChungTu, NK.SoHoaDon,                 dbo.Char2Date(NK.NgayHoaDon) as NgayHoaDon, NK.LoaiTien, NK.TyGia, sum(NK.SoPhatSinhNT) as SoTienGocNT,                 sum(NK.SoPhatSinh) as SoTienGoc, 0 as SoTienCanTruNT, 0 as SoTienCanTru, 0 as SoTienDuNT, 0 as SoTienDu,                NK.DienGiaiTongHop DienGiai, DT.TENVIET AS TENDOITUONG, NK.KhoaDoiTuongNo, NK.KhoaTaiKhoanNo         FROM GL_NhatKyChungTu NK         LEFT JOIN DM_TaiKhoan TK ON NK.KhoaTaiKhoanNo = TK.Khoa         LEFT JOIN DM_DOITUONG DT ON NK.KhoaDoiTuongNo = DT.KHOA         WHERE (TK.SoTaiKhoan = '1310' or TK.SoTaiKhoan = '1311') and NK.KhoaChungTu = '" + pKhoa + "'         GROUP BY NK.KhoaChungTu, NK.SoChungTu, dbo.Char2Date(NK.NgayChungTu), NK.SoHoaDon,  dbo.Char2Date(NK.NgayHoaDon),                NK.LoaiTien, NK.TyGia, NK.DienGiaiTongHop, DT.TENVIET, NK.KhoaDoiTuongNo, NK.KhoaTaiKhoanNo) A LEFT JOIN         (SELECT NK.KhoaChungTu, NK.SoChungTu, dbo.Char2Date(NK.NgayChungTu) as NgayChungTu, NK.SoHoaDon,                dbo.Char2Date(NK.NgayHoaDon) as NgayHoaDon, NK.LoaiTien, NK.TyGia, sum(NK.SoPhatSinhNT) as SoTienGocNT,                sum(NK.SoPhatSinh) as SoTienGoc, 0 as SoTienCanTruNT, 0 as SoTienCanTru, 0 as SoTienDuNT, 0 as SoTienDu,                NK.DienGiaiTongHop DienGiai, DT.TENVIET AS TENDOITUONG           FROM GL_NhatKyChungTu NK          LEFT JOIN DM_TaiKhoan TK ON NK.KhoaTaiKhoanCo = TK.Khoa          LEFT JOIN DM_DOITUONG DT ON NK.KhoaDoiTuongCo = DT.KHOA          WHERE (TK.SoTaiKhoan = '1310' or TK.SoTaiKhoan = '1311') and NK.KhoaChungTu = '" + pKhoa + "'          GROUP BY NK.KhoaChungTu, NK.SoChungTu, dbo.Char2Date(NK.NgayChungTu), NK.SoHoaDon,  dbo.Char2Date(NK.NgayHoaDon),                  NK.LoaiTien, NK.TyGia, NK.DienGiaiTongHop, DT.TENVIET) B ON A.KhoaChungTu = B.KHOACHUNGTU ";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoaChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mSoHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mNgayHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinhNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoPhatSinh = Conversions.ToDouble(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetDecimal));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuongNo = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTaiKhoanNo = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienGiaiTongHop
        {
            get
            {
                return this.mDienGiaiTongHop;
            }
            set
            {
                this.mDienGiaiTongHop = value;
            }
        }

        public string KhoaBoPhanCo
        {
            get
            {
                return this.mKhoaBoPhanCo;
            }
            set
            {
                this.mKhoaBoPhanCo = value;
            }
        }

        public string KhoaBoPhanNo
        {
            get
            {
                return this.mKhoaBoPhanNo;
            }
            set
            {
                this.mKhoaBoPhanNo = value;
            }
        }

        public string KhoaChungTu
        {
            get
            {
                return this.mKhoaChungTu;
            }
            set
            {
                this.mKhoaChungTu = value;
            }
        }

        public string KhoaDoiTuongCo
        {
            get
            {
                return this.mKhoaDoiTuongCo;
            }
            set
            {
                this.mKhoaDoiTuongCo = value;
            }
        }

        public string KhoaDoiTuongNo
        {
            get
            {
                return this.mKhoaDoiTuongNo;
            }
            set
            {
                this.mKhoaDoiTuongNo = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDongCo
        {
            get
            {
                return this.mKhoaHopDongCo;
            }
            set
            {
                this.mKhoaHopDongCo = value;
            }
        }

        public string KhoaHopDongNo
        {
            get
            {
                return this.mKhoaHopDongNo;
            }
            set
            {
                this.mKhoaHopDongNo = value;
            }
        }

        public string KhoaKhoanMucCo
        {
            get
            {
                return this.mKhoaKhoanMucCo;
            }
            set
            {
                this.mKhoaKhoanMucCo = value;
            }
        }

        public string KhoaKhoanMucNo
        {
            get
            {
                return this.mKhoaKhoanMucNo;
            }
            set
            {
                this.mKhoaKhoanMucNo = value;
            }
        }

        public string KhoaSanPhamCo
        {
            get
            {
                return this.mKhoaSanPhamCo;
            }
            set
            {
                this.mKhoaSanPhamCo = value;
            }
        }

        public string KhoaSanPhamNo
        {
            get
            {
                return this.mKhoaSanPhamNo;
            }
            set
            {
                this.mKhoaSanPhamNo = value;
            }
        }

        public string KhoaTaiKhoanCo
        {
            get
            {
                return this.mKhoaTaiKhoanCo;
            }
            set
            {
                this.mKhoaTaiKhoanCo = value;
            }
        }

        public string KhoaTaiKhoanNo
        {
            get
            {
                return this.mKhoaTaiKhoanNo;
            }
            set
            {
                this.mKhoaTaiKhoanNo = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NgayHoaDon
        {
            get
            {
                return this.mNgayHoaDon;
            }
            set
            {
                this.mNgayHoaDon = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public string SoHoaDon
        {
            get
            {
                return this.mSoHoaDon;
            }
            set
            {
                this.mSoHoaDon = value;
            }
        }

        public double SoPhatSinh
        {
            get
            {
                return this.mSoPhatSinh;
            }
            set
            {
                this.mSoPhatSinh = value;
            }
        }

        public double SoPhatSinhNT
        {
            get
            {
                return this.mSoPhatSinhNT;
            }
            set
            {
                this.mSoPhatSinhNT = value;
            }
        }

        public string SoSeri
        {
            get
            {
                return this.mSoSeri;
            }
            set
            {
                this.mSoSeri = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

